package com.itheima.bean;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * VO：（Value Object）值对象
 *
 * @Description:
 */

public class PageVO<T> implements Serializable {

    private Integer frist = 1;
    private Integer prevPage;
    private Integer nextPage;
    private Integer end;
    private Integer pageSize;
    private Integer page;
    private Integer totalPage;
    private Integer counts;

    //给集合数据默认值，防止空指针
    private List<T> items = Collections.EMPTY_LIST;

    public PageVO() {
    }

    /**
     * 初始化PgaeVo数据使用
     * @param pageSize
     * @param page
     * @param counts
     * @param items
     */
    public PageVO(Integer pageSize, Integer page, Integer counts, List<T> items) {
        this.pageSize = pageSize;
        this.page = page;
        this.counts = counts;
        this.items = items;

        // 总页数
        this.totalPage = this.counts % this.pageSize == 0 ? this.counts / this.pageSize : (this.counts / this.pageSize) + 1;

        // 上一页
        this.prevPage = this.page - 1;
        if (prevPage < 1) {
            prevPage = 1;
        }

        // 下一页
        this.nextPage = this.page + 1;
        if (nextPage > totalPage) {
            nextPage = totalPage;
        }


        // 末页
        this.end = this.totalPage;
    }

    public Integer getFrist() {
        return frist;
    }

    public void setFrist(Integer frist) {
        this.frist = frist;
    }

    public Integer getPrevPage() {
        return prevPage;
    }

    public void setPrevPage(Integer prevPage) {
        this.prevPage = prevPage;
    }

    public Integer getNextPage() {
        return nextPage;
    }

    public void setNextPage(Integer nextPage) {
        this.nextPage = nextPage;
    }

    public Integer getEnd() {
        return end;
    }

    public void setEnd(Integer end) {
        this.end = end;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getCounts() {
        return counts;
    }

    public void setCounts(Integer counts) {
        this.counts = counts;
    }

    public List<T> getItems() {
        return items;
    }

    public void setItems(List<T> items) {
        this.items = items;
    }
}
